package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmArchivesOperationTest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
@Repository
public interface AmArchivesOperationTestRepository extends JpaRepository<AmArchivesOperationTest, Integer> {
    
    /**
     * 根据电机ID查询试验数据
     */
    List<AmArchivesOperationTest> findByMotorId_MotorId(String motorId);
    
    /**
     * 根据试验类型查询试验数据
     */
    List<AmArchivesOperationTest> findByTestType(String testType);
    
    /**
     * 根据试验时间范围查询试验数据
     */
    List<AmArchivesOperationTest> findByTestTimeBetween(Date startTime, Date endTime);
    
    /**
     * 查询效率大于指定值的试验数据
     */
    List<AmArchivesOperationTest> findByEfficiencyGreaterThan(BigDecimal efficiency);
    
    /**
     * 查询指定电机的最新试验记录
     */
    @Query("SELECT t FROM AmArchivesOperationTest t WHERE t.motorId.motorId = :motorId ORDER BY t.testTime DESC")
    List<AmArchivesOperationTest> findLatestTestsByMotorId(@Param("motorId") String motorId, org.springframework.data.domain.Pageable pageable);
    
    /**
     * 查询指定电机的效率变化趋势
     */
    @Query("SELECT t.testTime, t.efficiency FROM AmArchivesOperationTest t WHERE t.motorId.motorId = :motorId AND t.testType = :testType ORDER BY t.testTime")
    List<Object[]> findEfficiencyTrend(@Param("motorId") String motorId, @Param("testType") String testType);
} 